package com.zrwl.poscloud.core.task.file;//package com.zrwl.poscloud.posfile.task;
//
//import com.zrwl.poscloud.posfile.config.ClientConfig;
//import com.zrwl.poscloud.posfile.entity.FileInfo;
//import com.zrwl.poscloud.posfile.entity.FileSyncClient;
//import com.zrwl.poscloud.posfile.service.FileInfoService;
//import com.zrwl.poscloud.posfile.service.SyncService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.SchedulingConfigurer;
//import org.springframework.scheduling.config.ScheduledTaskRegistrar;
//import org.springframework.scheduling.support.CronTrigger;
//import org.springframework.stereotype.Component;
//
//import java.util.Date;
//import java.util.List;
//
//@Component
//public class FileSyncTask implements SchedulingConfigurer {
//
//    @Autowired
//    ClientConfig clientConfig;
//
//    @Autowired
//    SyncService syncService;
//    @Autowired
//    FileInfoService fileInfoService;
//
//    @Override
//    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//
//        taskRegistrar.addTriggerTask(() -> {
//            System.out.println("----客户端文件同步计划----" + new Date().toString());
//            /***
//             * 1.从fileSyncClient 中得到uploadCode,downloadCode
//             * 2.fileInfo中查询sync大于uploadCode，且同步状态为1 的数据
//             *   上传到服务器
//             * 3.想服务器查询sync大于downloadCode的数据，
//             *   逐一下载到本地并保存
//             */
//            FileSyncClient fileSyncClient = syncService.getSyncCode();
//            List<FileInfo> record = fileInfoService.findListBySyncCode(fileSyncClient.getSyncUploadCode());
//            for (int i = 0; i < record.size(); i++) {
//                syncService.uploadFile(record.get(i));
//            }
//            syncService.downloadFile(null);
//        }, triggerContext -> {
//            //任务触发、可修改任务的执行周期
////            String CRON = "0 0 "+ clientConfig.getSyncFrequency()+" * * ?";//cron表达式 每天几点整触发
//            String CRON = "*/" + clientConfig.getSyncFrequency() + " * * * * ?";//cron表达式 此处测试每30秒触发
//            CronTrigger trigger = new CronTrigger(CRON);
//            return trigger.nextExecutionTime(triggerContext);
//        });
//    }
//}
//
